<include file="../Public/_header" />
<script>
//鼠标移动表格效果
$(document).ready(function(){
    $("tr[overstyle='on']").hover(
      function () {
        $(this).addClass("bg_hover");
      },
      function () {
        $(this).removeClass("bg_hover");
      }
    );
});

function checkon(o){
    if( o.checked == true ){
        $(o).parents('tr').addClass('bg_on') ;
    }else{
        $(o).parents('tr').removeClass('bg_on') ;
    }
}

function checkAll(o){
    if( o.checked == true ){
        $('input[name="checkbox"]').attr('checked','true');
        $('tr[overstyle="on"]').addClass("bg_on");
    }else{
        $('input[name="checkbox"]').removeAttr('checked');
        $('tr[overstyle="on"]').removeClass("bg_on");
    }
}

//获取已选择用户的ID数组
function getChecked() {
    var ids = new Array();
    $.each($('table input:checked'), function(i, n){
        ids.push( $(n).val() );
    });
    return ids;
}

function deleteField(ids) {
	var length = 0;
    if(ids) {
        length = 1;         
    }else {
        ids    = getChecked();
        length = ids.length;
        ids    = ids.toString();
    }
    if(ids=='') {
        ui.error('请先选择一个字段');
        return ;
    }
    if(confirm('您将删除'+length+'条记录，删除后无法恢复，确定继续？')) {
        $.post("{:U('admin/User/deleteField')}",{ids:ids},function(res){
            if(res=='1') {
                ui.success('删除成功');
                removeItem(ids);
            }else {
                ui.error('删除失败');
            }
        });
    }
}

function removeItem(ids) {
    ids = ids.split(',');
    for(i = 0; i < ids.length; i++) {
        $('#field_'+ids[i]).remove();
    }
}
</script>
<div class="so_main">
  <div class="page_tit">资料配置</div>
  <div class="Toolbar_inbox">
    <a href="{:U('admin/user/addfield')}" class="btn_a"><span>添加字段</span></a>
    <a href="javascript:void(0);" class="btn_a" onclick="deleteField();"><span>删除字段</span></a>
  </div>
  <div class="list">
  	<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th style="width:30px;">
        <input type="checkbox" id="checkbox_handle" onclick="checkAll(this)" value="0">
        <label for="checkbox"></label>
    </th>
    <th class="line_l">字段键名</th>
    <th class="line_l">字段名称</th>
    <th class="line_l">所属模块</th>
    <th class="line_l">是否启用</th>
    <th class="line_l">空间显示</th>
    <th class="line_l">操作</th>
  </tr>
	<volist id="vo" name="list">
	  <tr overstyle='on' id="field_{$vo.id}">
	    <td><input type="checkbox" name="checkbox" id="checkbox2" onclick="checkon(this)" value="{$vo.id}"></td>
	    <td>{$vo.fieldkey}</td>
	    <td>{$vo.fieldname}</td>
	    <td><switch name="vo.module"><case value="base">基本资料</case><case value="intro">个人情况</case><case value="contact">联系方式</case></switch></td>
	    <td><eq name="vo.status" value="1">是<else />否</eq></td>
	    <td><eq name="vo.showspace" value="1">是<else />否</eq></td>
	    <td><a href="javascript:void(0);" onclick="deleteField('{$vo['id']}');">删除</a></td>
	  </tr>
   </volist>
   </table>
  </div>
  <div class="Toolbar_inbox">
    <a href="{:U('admin/user/addfield')}" class="btn_a"><span>添加字段</span></a>
    <a href="javascript:void(0);" class="btn_a" onclick="deleteField();"><span>删除字段</span></a>
  </div>
</div>
<include file="../Public/_footer" />